package com.harmontronics.hanma.paas.paas.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Arrays;
import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import com.harmontronics.hanma.paas.paas.common.ResponseEntity;
import com.harmontronics.hanma.paas.paas.common.PageBase;
import cn.hutool.core.convert.Convert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.harmontronics.hanma.paas.paas.service.HmSysJobLogAppService;
import com.harmontronics.hanma.paas.paas.dto.job.output.HmSysJobLogResult;
import com.harmontronics.hanma.paas.paas.dto.job.input.HmSysJobLogCreateInput;
import com.harmontronics.hanma.paas.paas.dto.job.input.HmSysJobLogUpdateInput;
import com.harmontronics.hanma.paas.paas.domain.job.entity.HmSysJobLog;
import com.harmontronics.hanma.paas.paas.utils.ParamUtils;

import javax.validation.Valid;


/**
 * ${comments}
 *
 * @author paas-generator
 * @email paas-generator@harmontronics.com
 * @date 2021-04-21 14:38:01
 */
@RestController
@RequestMapping("/api/hmsysjoblog")
@Api(tags = {"任务日志"})
public class HmSysJobLogController {
    @Autowired
    private HmSysJobLogAppService hmSysJobLogappService;



    @GetMapping("/page/list")
    @ApiOperation("分页列表")
    public ResponseEntity<IPage<HmSysJobLog>> list(
            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNo,
            @ApiParam(value = "每页数据条数", defaultValue = "20") @RequestParam(required = false, defaultValue = "20") int pageSize,
            @RequestParam(required = false) String jobName,
            @RequestParam(required = false) String jobGroup,
            @RequestParam(required = false) String status){
        HmSysJobLog sysJobLog = new HmSysJobLog();
        sysJobLog.setJobName(jobName).setJobGroup(jobGroup).setStatus(status);
        IPage<HmSysJobLog> pageList = hmSysJobLogappService.list(new Page(pageNo, pageSize), sysJobLog);
        return ResponseEntity.ok(pageList);
    }

    /**
     * 信息
     */
    @GetMapping("/info")
    @ApiOperation("详情")
    public ResponseEntity<HmSysJobLogResult> info(@RequestParam Long jobLogId) {
        HmSysJobLog hmSysJobLog =hmSysJobLogappService.findById(jobLogId);
        HmSysJobLogResult result = BeanUtil.toBean(hmSysJobLog,HmSysJobLogResult.class);
        return ResponseEntity.ok(result);
    }

    /**
     * 保存
     */
    @PostMapping()
    @ApiOperation("保存")
    public ResponseEntity<String> save(@Valid @RequestBody HmSysJobLogCreateInput hmSysJobLogInput, BindingResult bindingResult) {
        ParamUtils.valid(bindingResult);
        HmSysJobLog hmSysJobLog =BeanUtil.toBean(hmSysJobLogInput,HmSysJobLog. class);
        hmSysJobLogappService.save(hmSysJobLog);
        return ResponseEntity.ok();
    }

    /**
     * 修改
     */
    @PutMapping
    @ApiOperation("修改")
    public ResponseEntity<String> update(@RequestBody HmSysJobLogUpdateInput hmSysJobLogInput, BindingResult bindingResult) {
        ParamUtils.valid(bindingResult);
        HmSysJobLog hmSysJobLog =BeanUtil.toBean(hmSysJobLogInput,HmSysJobLog. class);
        hmSysJobLogappService.update(hmSysJobLog);
        return ResponseEntity.ok();
    }


    /**
     * 删除
     */
    @DeleteMapping()
    @ApiOperation("删除")
    public ResponseEntity<String> delete(@RequestBody Long[] jobLogIds) {
        hmSysJobLogappService.remove(Arrays.asList(jobLogIds));
        return ResponseEntity.ok();
    }

}
